//
//  JSONViewController.m
//  RequestJSONDemo
//
//  Created by guyu on 14-1-20.
//  Copyright (c) 2014年 gavin. All rights reserved.
//

#import "JSONViewController.h"

@interface JSONViewController ()

@end

@implementation JSONViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self requestJSON];
}

- (void)requestJSON{
    //中国气象局
    NSString *str = @"http://www.weather.com.cn/data/sk/101010100.html";
    NSURL *strURL = [NSURL URLWithString:str];
    NSURLRequest *request = [NSURLRequest requestWithURL:strURL];
    
    [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];
    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
                                                                                        success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
    {
        NSDictionary *result = [NSDictionary dictionaryWithDictionary:JSON];
        NSLog(@"result : %@",request);
        NSArray *collection = [result objectForKey:@"weatherinfo"];
        //Mapping Model
        
        //请求成功，该干点什么
        
    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
        NSLog(@"errorInfo : %@",error);
        //请求失败，该干点什么
    }];
    
    [operation start];
}

@end
